{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A quick, practical intro to the Jupyter Notebook "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "\n",
    "The Jupyter Notebook is an **interactive computing environment** that enables users to author notebook documents that include: \n",
    "- Live code\n",
    "- Interactive widgets\n",
    "- Plots\n",
    "- Narrative text\n",
    "- Equations\n",
    "- Images\n",
    "- Video\n",
    "\n",
    "These documents provide a **complete and self-contained record of a computation** that can be converted to various formats and shared with others using email, [Dropbox](http://dropbox.com), version control systems (like git/[GitHub](http://github.com)) or [nbviewer.ipython.org](http://nbviewer.ipython.org)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Components\n",
    "\n",
    "The Jupyter Notebook combines three components:\n",
    "\n",
    "* **The notebook web application**: An interactive web application for writing and running code interactively and authoring notebook documents.\n",
    "* **Kernels**: Separate processes started by the notebook web application that runs users' code in a given language and returns output back to the notebook web application. The kernel also handles things like computations for interactive widgets, tab completion and introspection. \n",
    "* **Notebook documents**: Self-contained documents that contain a representation of all content visible in the notebook web application, including inputs and outputs of the computations, narrative\n",
    "text, equations, images, and rich media representations of objects. Each notebook document has its own kernel."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Notebook web application\n",
    "\n",
    "The notebook web application enables users to:\n",
    "\n",
    "* **Edit code in the browser**, with automatic syntax highlighting, indentation, and tab completion/introspection.\n",
    "* **Run code from the browser**, with the results of computations attached to the code which generated them.\n",
    "* See the results of computations with **rich media representations**, such as HTML, LaTeX, PNG, SVG, PDF, etc.\n",
    "* Create and use **interactive JavaScript wigets**, which bind interactive user interface controls and visualizations to reactive kernel side computations.\n",
    "* Author **narrative text** using the [Markdown](https://daringfireball.net/projects/markdown/) markup language.\n",
    "* Build **hierarchical documents** that are organized into sections with different levels of headings.\n",
    "* Include mathematical equations using **LaTeX syntax in Markdown**, which are rendered in-browser by [MathJax](http://www.mathjax.org/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Kernels\n",
    "\n",
    "Through Jupyter's kernel and messaging architecture, the Notebook allows code to be run in a range of different programming languages.  For each notebook document that a user opens, the web application starts a kernel that runs the code for that notebook. Each kernel is capable of running code in a single programming language and there are kernels available in over [100 programming languages](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels).\n",
    "\n",
    "[IPython](https://github.com/ipython/ipython) is the default kernel, it runs Python code.\n",
    "\n",
    "Each of these kernels communicate with the notebook web application and web browser using a JSON over ZeroMQ/WebSockets message protocol that is described [here](https://jupyter-client.readthedocs.io/en/latest/messaging.html#messaging). Most users don't need to know about these details, but it helps to understand that \"kernels run code.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Notebook documents\n",
    "\n",
    "Notebook documents contain the **inputs and outputs** of an interactive session as well as **narrative text** that accompanies the code but is not meant for execution. **Rich output** generated by running code, including HTML, images, video, and plots, is embeddeed in the notebook, which makes it a complete and self-contained record of a computation. \n",
    "\n",
    "When you run the notebook web application on your computer, notebook documents are just **files on your local filesystem with a `.ipynb` extension**. This allows you to use familiar workflows for organizing your notebooks into folders and sharing them with others using email, Dropbox and version control systems.\n",
    "\n",
    "Notebooks consist of a **linear sequence of cells**. There are three basic cell types:\n",
    "\n",
    "* **Code cells:** Input and output of live code that is run in the kernel\n",
    "* **Markdown cells:** Narrative text with embedded LaTeX equations\n",
    "* **Raw cells:** Unformatted text that is included, without modification, when notebooks are converted to different formats using nbconvert\n",
    "\n",
    "Internally, notebook documents are **[JSON](http://en.wikipedia.org/wiki/JSON) data** with **binary values [base64](http://en.wikipedia.org/wiki/Base64)** encoded. This allows them to be **read and manipulated programmatically** by any programming language. Because JSON is a text format, notebook documents are version control friendly.\n",
    "\n",
    "**Notebooks can be exported** to different static formats including HTML, reStructeredText, LaTeX, PDF, and slide shows using Jupyter's `nbconvert` utility.\n",
    "\n",
    "Furthermore, any notebook document available from a **public URL on or GitHub can be shared** via http://nbviewer.jupyter.org. This service loads the notebook document from the URL and renders it as a static web page. The resulting web page may thus be shared with others **without their needing to install Jupyter**."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Body\n",
    "\n",
    "The body of a notebook is composed of cells. Each cell contains either markdown, code input, code output, or raw text. Cells can be included in any order and edited at-will, allowing for a large ammount of flexibility for constructing a narrative.\n",
    "\n",
    "- **Markdown cells** - These are used to build a nicely formatted narrative around the code in the document. The majority of this lesson is composed of markdown cells.\n",
    "\n",
    "- **Code cells** - These are used to define the computational code in the document. They come in two forms: the *input cell* where the user types the code to be executed, and the *output cell* which is the representation of the executed code. Depending on the code, this representation may be a simple scalar value, or something more complex like a plot or an interactive widget.\n",
    "\n",
    "- **Raw cells** - These are used when text needs to be included in raw form, without execution or transformation.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm a code cell!\n"
     ]
    }
   ],
   "source": [
    "print(\"I'm a code cell!\")"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "I'm a **raw cell, _no formatting is applied, $x+1$ is not treated as math. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Modality\n",
    "\n",
    "The notebook user interface is *modal*. This means that the keyboard behaves differently depending upon the current mode of the notebook. A notebook has two modes: **edit** and **command**.\n",
    "\n",
    "**Edit mode** is indicated by a blue cell border and a prompt showing in the editor area. When a cell is in edit mode, you can type into the cell, like a normal text editor.\n",
    "\n",
    "<img src=\"images/edit_mode.png\">\n",
    "\n",
    "**Command mode** is indicated by a grey cell background. When in command mode, the structure of the notebook can be modified as a whole, but the text in individual cells cannot be changed. Most importantly, the keyboard is mapped to a set of shortcuts for efficiently performing notebook and cell actions. For example, pressing **`c`** when in command mode, will copy the current cell; no modifier is needed.\n",
    "\n",
    "<img src=\"images/command_mode.png\">\n",
    "\n",
    "Enter edit mode by pressing `Enter` or using the mouse to click on a cell's editor area.\n",
    "\n",
    "Enter command mode by pressing `Esc` or using the mouse to click *outside* a cell's editor area.\n",
    "\n",
    "Do not attempt to type into a cell when in command mode; unexpected things will happen!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Mouse navigation\n",
    "\n",
    "The first concept to understand in mouse-based navigation is that **cells can be selected by clicking on them.** The currently selected cell is indicated with a blue outline or gray background depending on whether the notebook is in edit or command mode. Clicking inside a cell's editor area will enter edit mode. Clicking on the prompt or the output area of a cell will enter command mode.\n",
    "\n",
    "The second concept to understand in mouse-based navigation is that **cell actions usually apply to the currently selected cell**. For example, to run the code in a cell, select it and then click the <button class='btn btn-default btn-xs'><i class=\"fa fa-play icon-play\"></i></button> button in the toolbar or the **`Run -> Run Selected Cells`** menu item. Similarly, to copy a cell, select it and then click the <button class='btn btn-default btn-xs'><i class=\"fa fa-copy icon-copy\"></i></button> button in the toolbar or the **`Edit -> Copy`** menu item. With this simple pattern, it should be possible to perform nearly every action with the mouse.\n",
    "\n",
    "Markdown cells have one other state which can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, a nice formatted representation of the cell's contents will be presented. When they are unrendered, the raw text source of the cell will be presented. To render the selected cell with the mouse, click the <button class='btn btn-default btn-xs'><i class=\"fa fa-play icon-play\"></i></button> button in the toolbar or the **`Run -> Run Selected Cells`** menu item. To unrender the selected cell, double click on the cell."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Keyboard Navigation\n",
    "\n",
    "The modal user interface of the Jupyter Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode.\n",
    "\n",
    "The most important keyboard shortcuts are **`Enter`**, which enters edit mode, and **`Esc`**, which enters command mode.\n",
    "\n",
    "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts. In command mode, the entire keyboard is available for shortcuts, so there are many more possibilities.\n",
    "\n",
    "The following shortcuts have been found to be the most useful in day-to-day tasks:\n",
    "\n",
    "- Basic navigation: **`enter`**, **`shift-enter`**, **`up/k`**, **`down/j`**\n",
    "- Saving the notebook: **`s`**\n",
    "- Cell types: **`y`**, **`m`**, **`r`**\n",
    "- Cell creation: **`a`**, **`b`**\n",
    "- Cell editing: **`x`**, **`c`**, **`v`**, **`d`**, **`z`**, **`ctrl+shift+-`**\n",
    "- Kernel operations: **`i`**, **`.`**\n",
    "\n",
    "You can fully customize JupyterLab's keybindings by accessing the **`Settings -> Advanced Settings Editor`** menu item."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Running Code"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First and foremost, the Jupyter Notebook is an interactive environment for writing and running code. Jupyter is capable of running code in a wide range of languages. However, this notebook, and the default kernel in Jupyter, runs Python code."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code cells allow you to enter and run Python code\n",
    "\n",
    "Run a code cell using `Shift-Enter` or pressing the <button class='btn btn-default btn-xs'><i class=\"icon-play fa fa-play\"></i></button> button in the toolbar above:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n"
     ]
    }
   ],
   "source": [
    "print(a + 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note the difference between the above printing statement and the operation below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = _"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When a value is *returned* by a computation, it is displayed with a number, that tells you this is the output value of a given cell.  You can later refere to any of these values (should you need one that you forgot to assign to a named variable). The last three are available respectively as auto-generated variables called `_`, `__` and `___` (one, two and three underscores). In addition to these three convenience ones for recent results, you can use `_N`, where N is the number in `[N]`, to access any numbered output.\n",
    "\n",
    "\n",
    "There are two other keyboard shortcuts for running code:\n",
    "\n",
    "* `Alt-Enter` runs the current cell and inserts a new one below.\n",
    "* `Ctrl-Enter` run the current cell and enters command mode."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Managing the IPython Kernel\n",
    "\n",
    "Code is run in a separate process called the IPython Kernel.  The Kernel can be interrupted or restarted.  Try running the following cell and then hit the <button class='btn btn-default btn-xs'><i class='icon-stop fa fa-stop'></i></button> button in the toolbar above."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m-------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-18-c20d360cf4b6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import time\n",
    "time.sleep(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the Kernel dies you will be prompted to restart it. Here we call the low-level system libc.time routine with the wrong argument via\n",
    "ctypes to segfault the Python interpreter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "from ctypes import CDLL\n",
    "# This will crash a Linux or Mac system\n",
    "# equivalent calls can be made on Windows\n",
    "dll = 'dylib' if sys.platform == 'darwin' else 'so.6'\n",
    "libc = CDLL(\"libc.%s\" % dll) \n",
    "libc.time(-1)  # BOOM!!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cell menu\n",
    "\n",
    "The \"Run\" menu has a number of items for running code in different ways, including\n",
    "\n",
    "* Run Selected Cells\n",
    "* Run All Cells\n",
    "* Run Selected Cell or Current Line in Console\n",
    "* Run All Above Selected Cell\n",
    "* Run  Selected Cell and All Below\n",
    "* Restart Kernel and Run All Cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Restarting the kernels\n",
    "\n",
    "The kernel maintains the state of a notebook's computations. You can reset this state by restarting the kernel. This is done by clicking on the <button class='btn btn-default btn-xs'><i class='fa fa-repeat icon-repeat'></i></button> in the toolbar above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## sys.stdout and sys.stderr\n",
    "\n",
    "The stdout and stderr streams are displayed as text in the output area."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hi, stdout\n"
     ]
    }
   ],
   "source": [
    "print(\"hi, stdout\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "hi, stderr\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "print('hi, stderr', file=sys.stderr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Output is asynchronous\n",
    "\n",
    "All output is displayed as it is generated in the Kernel: instead of blocking on the execution of the entire cell, output is made available to the Notebook immediately as it is generated by the kernel (even though the whole cell is submitted for execution as a single unit).\n",
    "\n",
    "If you execute the next cell, you will see the output one piece at a time, not all at the end:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "import time, sys\n",
    "for i in range(8):\n",
    "    print(i)\n",
    "    time.sleep(0.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Large outputs\n",
    "\n",
    "To better handle large outputs, the output area can be collapsed. Run the following cell and then click on the vertical blue bar to the left of the output:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n"
     ]
    }
   ],
   "source": [
    "for i in range(50):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "# Markdown Cells\n",
    "\n",
    "Text can be added to IPython Notebooks using Markdown cells.  Markdown is a popular markup language that is a superset of HTML. Its specification can be found here:\n",
    "\n",
    "<http://daringfireball.net/projects/markdown/>\n",
    "\n",
    "You can view the source of a cell by double clicking on it, or while the cell is selected in command mode, press `Enter` to edit it. One A cell has been editted, use `Shift-Enter` to re-render it. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Markdown basics\n",
    "\n",
    "You can make text *italic* or **bold**.\n",
    "\n",
    "You can build nested itemized or enumerated lists:\n",
    "\n",
    "* One\n",
    "    - Sublist\n",
    "        - This\n",
    "  - Sublist\n",
    "        - That\n",
    "        - The other thing\n",
    "* Two\n",
    "  - Sublist\n",
    "* Three\n",
    "  - Sublist\n",
    "\n",
    "Now another list:\n",
    "\n",
    "1. Here we go\n",
    "    1. Sublist\n",
    "    2. Sublist\n",
    "2. There we go\n",
    "3. Now this\n",
    "\n",
    "\n",
    "You can add horizontal rules:\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is a blockquote:\n",
    "\n",
    "> Beautiful is better than ugly.\n",
    "> Explicit is better than implicit.\n",
    "> Simple is better than complex.\n",
    "> Complex is better than complicated.\n",
    "> Flat is better than nested.\n",
    "> Sparse is better than dense.\n",
    "> Readability counts.\n",
    "> Special cases aren't special enough to break the rules.\n",
    "> Although practicality beats purity.\n",
    "> Errors should never pass silently.\n",
    "> Unless explicitly silenced.\n",
    "> In the face of ambiguity, refuse the temptation to guess.\n",
    "> There should be one-- and preferably only one --obvious way to do it.\n",
    "> Although that way may not be obvious at first unless you're Dutch.\n",
    "> Now is better than never.\n",
    "> Although never is often better than *right* now.\n",
    "> If the implementation is hard to explain, it's a bad idea.\n",
    "> If the implementation is easy to explain, it may be a good idea.\n",
    "> Namespaces are one honking great idea -- let's do more of those!\n",
    "\n",
    "\n",
    "And shorthand for links:\n",
    "\n",
    "[IPython's website](http://ipython.org)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can add headings using Markdown's syntax:\n",
    "\n",
    "# Heading 1\n",
    "\n",
    "# Heading 2\n",
    "\n",
    "## Heading 2.1\n",
    "\n",
    "## Heading 2.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Embedded code\n",
    "\n",
    "You can embed code meant for illustration instead of execution in Python:\n",
    "\n",
    "    def f(x):\n",
    "        \"\"\"a docstring\"\"\"\n",
    "        return x**2\n",
    "\n",
    "or other languages:\n",
    "\n",
    "    if (i=0; i<n; i++) {\n",
    "      printf(\"hello %d\\n\", i);\n",
    "      x += 4;\n",
    "    }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## LaTeX equations\n",
    "\n",
    "Courtesy of MathJax, you can include mathematical expressions both inline: \n",
    "$e^{i\\pi} + 1 = 0$  and displayed:\n",
    "\n",
    "$$e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i$$\n",
    "\n",
    "Use single dolars delimiter for inline math, so `$thisisinline\\int math$`  will give $this is inline\\int math$, for example to refer to variable within text. \n",
    "\n",
    "Double dollars `$$\\int_0^{2\\pi} f(r, \\phi) \\partial \\phi $$` is used for standalone formulas:\n",
    "\n",
    "$$\\int_0^{2\\pi} f(r, \\phi) \\partial \\phi $$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Github flavored markdown (GFM)\n",
    "\n",
    "The Notebook webapp support Github flavored markdown meaning that you can use triple backticks for code blocks \n",
    "<pre>\n",
    "```python\n",
    "print \"Hello World\"\n",
    "```\n",
    "\n",
    "```javascript\n",
    "console.log(\"Hello World\")\n",
    "```\n",
    "</pre>\n",
    "\n",
    "Gives \n",
    "```python\n",
    "print \"Hello World\"\n",
    "```\n",
    "\n",
    "```javascript\n",
    "console.log(\"Hello World\")\n",
    "```\n",
    "\n",
    "And a table like this : \n",
    "\n",
    "<pre>\n",
    "| This | is   |\n",
    "|------|------|\n",
    "|   a  | table| \n",
    "</pre>\n",
    "\n",
    "A nice HTML Table\n",
    "\n",
    "| This | is   |\n",
    "|------|------|\n",
    "|   a  | table| "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## General HTML\n",
    "\n",
    "Because Markdown is a superset of HTML you can even add things like HTML tables:\n",
    "\n",
    "<table>\n",
    "<tr>\n",
    "<th>Header 1</th>\n",
    "<th>Header 2</th>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>row 1, cell 1</td>\n",
    "<td>row 1, cell 2</td>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>row 2, cell 1</td>\n",
    "<td>row 2, cell 2</td>\n",
    "</tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Local files\n",
    "\n",
    "If you have local files in your Notebook directory, you can refer to these files in Markdown cells directly:\n",
    "\n",
    "    [subdirectory/]<filename>\n",
    "\n",
    "For example, in the images folder, we have the Python logo:\n",
    "\n",
    "    <img src=\"images/python-logo.svg\" />\n",
    "\n",
    "<img src=\"images/python-logo.svg\" />\n",
    "\n",
    "and a video with the HTML5 video tag:\n",
    "\n",
    "    <video controls src=\"images/animation.m4v\" />\n",
    "\n",
    "<video controls src=\"images/animation.m4v\" />\n",
    "\n",
    "These do not embed the data into the notebook file, and require that the files exist when you are viewing the notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Security of local files\n",
    "\n",
    "Note that this means that the IPython notebook server also acts as a generic file server\n",
    "for files inside the same tree as your notebooks.  Access is not granted outside the\n",
    "notebook folder so you have strict control over what files are visible, but for this\n",
    "reason it is highly recommended that you do not run the notebook server with a notebook\n",
    "directory at a high level in your filesystem (e.g. your home directory).\n",
    "\n",
    "When you run the notebook in a password-protected manner, local file access is restricted\n",
    "to authenticated users unless read-only views are active."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Typesetting Equations\n",
    "\n",
    "The Markdown parser included in IPython is MathJax-aware.  This means that you can freely mix in mathematical expressions using the [MathJax subset of Tex and LaTeX](http://docs.mathjax.org/en/latest/tex.html#tex-support).  \n",
    "\n",
    "You can use single-dollar signs to include inline math, e.g. `$e^{i \\pi} = -1$` will render as $e^{i \\pi} = -1$, and double-dollars for displayed math:\n",
    "\n",
    "```\n",
    "$$\n",
    "e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i\n",
    "$$\n",
    "```\n",
    "\n",
    "renders as:\n",
    "\n",
    "$$\n",
    "e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i\n",
    "$$\n",
    "\n",
    "You can also use more complex LaTeX constructs for displaying math, such as:\n",
    "\n",
    "```\n",
    "\\begin{align}\n",
    "\\dot{x} & = \\sigma(y-x) \\\\\n",
    "\\dot{y} & = \\rho x - y - xz \\\\\n",
    "\\dot{z} & = -\\beta z + xy\n",
    "\\end{align}\n",
    "```\n",
    "\n",
    "to produce the Lorenz equations:\n",
    "\n",
    "\\begin{align}\n",
    "\\dot{x} & = \\sigma(y-x) \\\\\n",
    "\\dot{y} & = \\rho x - y - xz \\\\\n",
    "\\dot{z} & = -\\beta z + xy\n",
    "\\end{align}\n",
    "\n",
    "Please refer to the MathJax documentation for a comprehensive description of which parts of LaTeX are supported, but note that Jupyter's support for LaTeX is **limited to mathematics**. You can **not** use LaTeX typesetting constrcuts for text or document structure, for text formatting you should restrict yourself to Markdown syntax."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
